<template>
  <div class="login-container">

    <div class="Bgc">
      <div class="img">
        <img src="http://likede2-admin.itheima.net/img/logo.595745bd.png" alt="">
      </div>
      <div class="logo" />
      <div class="bdk">
        <div class="form">
          <el-card shadow="never" class="login-card">
            <!--登录表单-->
            <el-form ref="loginForm" :model="loginForm" status-icon :rules="rules">
              <el-form-item prop="username">
                <el-input v-model="loginForm.username" prefix-icon="el-icon-mobile-phone" placeholder="请输入账号" />
              </el-form-item>
              <el-form-item prop="password">
                <el-input v-model="loginForm.password" show-password type="password" autocomplete="off" prefix-icon="el-icon-lock" />
              </el-form-item>
              <el-form-item prop="yzm">
                <el-input v-model="loginForm.yzm" autosize autocomplete="off" prefix-icon="el-icon-circle-check" placeholder="请输入验证码" />
                <img class="q" src="https://likede2-java.itheima.net/api/user-service/user/imageCode/JdD17AKP6w9pS4TmeuTRU76plbfVhq1x" alt="">
              </el-form-item>
              <el-button type="primary" style="width:448px;height:52px;background-color:#6d7ff0" @click="submitForm()">登录</el-button>
            </el-form>
          </el-card>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'Login',
  data() {
    return {
      loginForm: {
        username: '',
        password: '123456',
        yzm: ''
      },
      // 校验步骤
      // ①首先给需要校验的表单绑定动态model和rules，
      // ②给要校验的字段绑定校验规则 例:prop="username" 注意要给校验字段下面的input框双向绑定表单里的内容
      // ③输入校验规则rules:{xxx:[{}]},注意xxx要与prop绑定的名字一致
      rules: {
        // required是否必填
        username: [{ required: true, message: '请输入账户', trigger: 'blur' },
          { min: 6, max: 16, message: '请输入6到16位字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 16, message: '密码在6到16位之间', trigger: 'blur' }
        ],
        yzm: [
          // 第一个参数是校验规则,第二个参数是校验的值,第三个是一个回调函数直接调用表示通过校验
          // callback(new Error('请勾选用户协议'))没有通过，并提示
          // validator自定义校验规则
          { required: true, message: '请输入验证码', trigger: 'blur' },
          { min: 1, max: 4, message: '请输入正确的验证码', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm() {
      // 获取loginForm上的方法，判断校验是否通过，一般是布尔值
      this.$refs.loginForm.validate((pass) => {
        // 如果为true则登录成功
        if (pass) {
          console.log('去登录了')
        }
      })
    }
  //   async submitForm() {
  //     await this.$refs.loginForm.validate()
  //     console.log('去登录')
  //   }// 如果校验失败会返回一个promise实例
  // }
  }
}
</script>
<style lang="scss">
.login-container {
  display: flex;
  align-items: stretch;
  height: 100vh;
  .logo {
    flex: 3;
    // background: rgba(38, 72, 176) url(../../assets/common/login_back.png)
      // no-repeat center / cover;
    border-top-right-radius: 60px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    padding: 0 100px;
    .icon {
      background: url(../../assets/common/logo.png) no-repeat 70px center /
        contain;
      width: 300px;
      height: 50px;
      margin-bottom: 50px;
    }
    p {
      color: #fff;
      font-size: 18px;
      margin-top: 20px;
      width: 300px;
      text-align: center;
    }
  }
  .form {
    flex: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
text-align: center;
    width: 448px;
    height: 300px;
    .el-card {
      border: none;
      padding: 0;
    }
    h1 {
      padding-left: 20px;
      font-size: 24px;
    }
    .el-input {
      width: 470px;
      height: 52px;
      .el-input__inner {
        width: 470px;
      height: 52px;
        background:white;
      }
    }
    .el-checkbox {
      color:#606266;
    }
  }
}
.Bgc{
  width: 100%;
 height: 100%;
 background-image: url("http://likede2-admin.itheima.net/img/background.be4fae7d.png");
 background-size: cover;
padding: 60px 10px;
}
.bdk{
  width: 518px;
  height: 388px;
  background-color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  margin:10% auto;
  border-radius: 10px;
  }
  .img{
    text-align: center;
   margin-bottom: -200px;
   text-align: center;
   img{
     width: 96px;
    height: 96px;
   }
  }
.dl{
  text-align: center;
}
.q{
  position: absolute;
  margin-left: -131px;
  margin-top: 0px;
  img{
    height: 58px;
    margin-top: 5px;
  }
}
</style>
